package com.itheima.test3;

import java.io.*;
import java.net.Socket;

/*
上传文件的 客户端
 */
public class KehuClient {
    public static void main(String[] args) throws IOException {
        //创建客户端对象
        Socket socket = new Socket("127.0.0.1", 8888);
        //创建本地输入流
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("C:\\Users\\Administrator\\Desktop\\美女.jpg"));

        // 获取输出流
        OutputStream os = socket.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(os);
        //读写
        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }
        //给一个结束标记
        socket.shutdownOutput();
        //获取 服务端的响应
        InputStream is = socket.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String s;
        while ((s=reader.readLine())!=null){
            System.out.println(s);
        }

        //释放资源
        bis.close();
        socket.close();


    }
}
